using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Playables;
using UnityEngine.Timeline;
using Object = UnityEngine.Object;

namespace com.yoozoo.gta
{
    public class TimelineChangeModel : MonoBehaviour
    {
        public PlayableDirector Director;

        public GameObject OriRole;

        public Object RoleObj;

        public Object PosObj;
        // Start is called before the first frame update
        private void Awake()
        {
            Director = GetComponent<PlayableDirector>();
        }

        void Start()
        {
            
            GetAllOuts();
        }

        // Update is called once per frame
        void Update()
        {
        
        }
        private void GetAllOuts()
        {
           
            foreach (PlayableBinding item in Director.playableAsset.outputs)
            {
                //Debug.LogError("item.streamName = " + item.streamName);
                if (item.streamName == "Animation Track")
                {
                    RoleObj = item.sourceObject;
                }
                else if (item.streamName == "Animation Track (1)")
                {
                    PosObj = item.sourceObject;
                }
                
            }
        }
        public void SetGenericBindAni(Animator ani)
        {
            if (RoleObj != null)
            {
                Director.SetGenericBinding(RoleObj, ani);
            }
            if (PosObj != null)
            {
                Director.SetGenericBinding(PosObj, ani);
            }

            if (OriRole)
            {
                OriRole.SetActive(false);
            }
        }
    }
}
